package de.hauschild.gmltracer.gml.impl.control;

import de.hauschild.gmltracer.gml.Environment;
import de.hauschild.gmltracer.gml.TokenStack;
import de.hauschild.gmltracer.gml.impl.AbstractToken;
import de.hauschild.gmltracer.gml.impl.GmlInterpreter;

/**
 * Applies the {@link FunctionToken} at the top of the {@link TokenStack}.
 * 
 * @author Klaus Hauschild
 * @since 1.0.0
 */
public class ApplyToken extends AbstractToken {

  private static final GmlInterpreter GML_INTERPRETER = new GmlInterpreter();

  @Override
  public void evaluate(final Environment environment, final TokenStack tokenStack) {
    final FunctionToken function = tokenStack.pop(FunctionToken.class);

    GML_INTERPRETER.interpret(function.getEnvironment(), tokenStack, function.getTokenList());
  }

  @Override
  public String toString() {
    return "apply"; //$NON-NLS-1$
  }
}
